package generadorDescriptores.test;

import generadorDescriptores.dom.DimensionDom;
import generadorDescriptores.dom.DimensionPropertyDom;
import generadorDescriptores.dom.DimensionsDom;
import generadorDescriptores.dom.FacttableDom;
import generadorDescriptores.dom.JoinDom;
import generadorDescriptores.dom.JoinsDom;
import generadorDescriptores.dom.XmlDocument;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

import com.project.frba.bi.descriptor.Join;

public class PruebaXml {
	public static void main(String[] args) {
//		String filepath;
//		XmlFile xml;
//		
//		filepath = Parameters.getDescriptorsFolderPath() + "\\countSales_descriptor.xml";
//		xml = new XmlFile(filepath);
//		xml.load();
//		
//		NodeList ele = xml.getDocument().getElementsByTagName("join");
//		String tabla = ele.item(0).getAttributes().getNamedItem("table").getNodeValue();
//		System.out.println(tabla);
		
		XmlDocument docu = new XmlDocument();
		docu.setAttributes("sales", "cantidad de ventas", "general");
		Document doc = docu.getDocument();
		
		//agregamos la facttable
		FacttableDom fact = new FacttableDom(doc);
		fact.setAttributes("sale", "count(*)", "long","com.project.frba.bifront.client.model.format.UnitFormatter");
		docu.addFacttable(fact);
		
		//Agregamos el tag joins
		JoinsDom joins = new JoinsDom(doc);
		fact.addJoins(joins);
		
		//Agregamos un join
		JoinDom join = new JoinDom(doc);
		join.setAttributes("sl", "saleline");
		joins.addJoin(join);
		
		//agregamos el tag dimensions
		DimensionsDom dimensions = new DimensionsDom(doc);
		fact.addDimensions(dimensions);
		
		//agregamos una dimension
		DimensionDom dimension = new DimensionDom(doc);
		dimension.setAttributes("product");
		dimensions.addDimension(dimension);
		
		//Agregamos una property para esa dimension
		DimensionPropertyDom prop = new DimensionPropertyDom(doc);
		prop.setCommonAttributes("productName", "product", "name", "Nombre de producto");
		prop.setAttributeDefault("col");
		dimension.addProperty(prop);
		
		
		
		//to show the xml
		TransformerFactory xformFactory 
	       = TransformerFactory.newInstance();  
	      Transformer idTransform  = null;
		try {
			idTransform = xformFactory.newTransformer();
		} catch (TransformerConfigurationException e) {
			e.printStackTrace();
		}
	      Source input = new DOMSource(doc);
	      Result output = new StreamResult(System.out);
	      try {
			idTransform.transform(input, output);
		} catch (TransformerException e) {
			e.printStackTrace();
		}
		
		
	}

}
